package com.yueka.controller;

import com.yueka.pojo.R;
import com.yueka.pojo.entity.instrument_category.InstrumentCategory;
import com.yueka.service.InstrumentCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/instrumentCategory")
@RestController
public class InstrumentCategoryController {

    @Autowired
    private InstrumentCategoryService instrumentCategoryService;

    @GetMapping("/list")
    public R list() {
        return R.success(instrumentCategoryService.getAll());
    }

    @GetMapping("/delete")
    public R delete(Integer[] ids) {
        Integer count = instrumentCategoryService.delete(ids);
        if (count > 0) {
            return R.success(count);
        }
        return R.error("删除失败，请重试！");
    }

    @PostMapping("/insert")
    public R insert(@RequestBody InstrumentCategory instrumentCategory) {
        Integer count = instrumentCategoryService.insert(instrumentCategory);
        if (count > 0) {
            return R.success(count);
        }
        return R.error("添加失败，请重试！");
    }

    @PostMapping("/update")
    public R update(@RequestBody InstrumentCategory instrumentCategory) {
        Integer count = instrumentCategoryService.update(instrumentCategory);
        if (count > 0) {
            return R.success(count);
        }
        return R.error("更新失败，请重试！");
    }
}
